<template>
  <basic-container>
    <div class="card-border">
    <card-header :header-data="headerData"></card-header>
    <avue-crud :data="topicData"
               :option="option"
               :page="page"
               :table-loading="tableLoading"
               @size-change="sizeChange"
               @current-change="currentChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               class="avuecrud">
      <template slot="menuRight">
        <el-button type="warning" size="small" @click="exportTopicData()">导出</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <div class="menu-title" @click.stop="feedBack(scope.row,scope.index)" v-if="scope.row.state == '1'">
          <i class="iconfont iconalter" style="color: #ec950a;"></i>
          <p class="menu-title-text">反馈</p>
        </div>
      </template>
    </avue-crud>
    </div>
  </basic-container>
</template>
<script>
import { mapGetters } from "vuex";
import {getTopicPage,exportTopicData,exportTopicDataExcel} from "@/api/planning/message";
export default {
  name: "discussion",
  data() {
    return {
      headerData:{
        title:'会商反馈'
      },
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading:false,
      topicData: [],
      option: {
        page: true,
        addBtn: false,
        editBtn: false,
        addRowBtn: false,
        indexLabel: "序号",
        index: true,
        cellBtn: false,
          indexWidth:70,
        delBtn: false,
        columnBtn: false,
        refreshBtn: false,
        filterBtn: false,
        searchBtn: false,
        menuWidth:100,
        keyId: "id",
        column: [
          {
            label: "会商标题",
            prop: "title",
            width: 350,
            cell: true,
            search:true,
            formatter: function (row, value, label, column) {
              return '<a style="cursor: pointer;" onclick="feedBackDetail(\'' + row.topicId + '\')">' + value + '</a>';
            }
          },
          {
            label: "会商说明",
            prop: "description",
            cell: true
          }
        ]
      },
      titleLikeSearch:''
    };
  },
  computed: mapGetters([
    "userInfo"
  ]),
  created(){
    this.getTotal();
    this.getTopicList(this.page);
    window.feedBackDetail = this.feedBackDetail;
  },
  methods: {
    getTotal(){
      getTopicPage({
        current: this.page.currentPage,
        size: this.page.pageSize,
        admins:1,
        userIds:this.userInfo.userId,
        state:'1'
      }).then(response => {
        this.$emit("getTotal", response.data.data.total)
      })
    },
    getTopicList(page, params) {
      this.tableLoading = true;
      getTopicPage(Object.assign({
        current: page.currentPage,
        size: page.pageSize,
        admins:1,
        userIds:this.userInfo.userId,
        state:'1',
      },params)).then(response => {
        this.topicData = response.data.data.records;
        this.page.total = response.data.data.total;
        this.tableLoading = false
      })
    },

    searchReset() {
      this.titleLikeSearch = '';
      let params = {
        titleLike:this.titleLikeSearch,
      };
      this.getTopicList(this.page,params);
    },
    //搜索回调
    searchChange (params) {
      this.page.currentPage = 1
      this.getTopicList(this.page, this.dealSearchParam(params));
    },
    // 处理搜索过滤
    dealSearchParam(params) {
      if (params.title) {
        params.titleLike = params.title;
      }
      this.titleLikeSearch = params.title;
      return params;
    },
    currentChange(currentPage) {
      var page = this.page;
      page.currentPage = currentPage;
      let params = {
        titleLike:this.titleLikeSearch,
      };
      this.getTopicList(page,params);
    },
    sizeChange(pageSize) {
      var page = this.page;
      page.pageSize = pageSize;
      let params = {
        titleLike:this.titleLikeSearch,
      };
      this.getTopicList(page,params);
    },

    // 反馈
    feedBack(row,index) {
      //   this.$router.$avueRouter.group = item.group;
      this.$router.push({
        path: "/feedBack",
        query:{
          topicId:row.topicId,
          detail:false
        }
      });
    },
    // 详情
    feedBackDetail(topicId) {
      this.$router.push({
        path: "/feedBack",
        query:{
          topicId,
          detail:true
        }
      });
    },
    exportTopicData(){
      this.$confirm("确定要导出会商反馈列表吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        exportTopicDataExcel({
          admins:1,
          userIds:this.userInfo.userId,
          state:'1'
        }).then(response => {
          let exportFileName = "会商反馈列表.xlsx";
          this.download(response.data, exportFileName)
        });
      })
    },
    // 下载文件
    download(data, filename) {
      if (data == null) {

      } else {
        let url = window.URL.createObjectURL(new Blob([data]));
        let link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', filename);
        document.body.appendChild(link);
        link.click()
      }
    },
  }
};
</script>

<style lang="scss" scoped>

</style>
